package net.mingsoft.report_data.util;

import java.util.HashMap;
import java.util.Map;

/**
 * @author gengfa
 * @date 22/03/24
 */
public class ArabNumber {
    public static void main(String[] args) {
        System.out.println(toChinese(12344));
    }

    private static final String[] CHINESE = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
    private static final String[] UNIT = { "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千" };

    private static final String TEN = "一十";

    private ArabNumber() {}

    public static String toChinese(int number) {
        char[] numChar = String.valueOf(number).toCharArray();
        StringBuilder sb =new StringBuilder();
        int size=numChar.length;
        for (int i = 0; i < numChar.length; i++) {
            int num = Integer.parseInt(String.valueOf(numChar[i]));
            if(i!=0){
                sb.append(UNIT[size - i - 1]).append(CHINESE[num]);
            }else{
                sb.append(CHINESE[num]);
            }
        }
        String s = sb.toString();
        if (s.startsWith(TEN)) {
            s = s.replace(TEN, UNIT[0]);
        }
        if (s.endsWith(CHINESE[0])) {
            s = s.substring(0, s.length()-1);
        }
        return s;
    }
}
